<#include "../base.ftl"/>
<#macro css>

</#macro>

<#macro js>

</#macro>

<#macro title>
广大物流云平台
</#macro>
<#macro script>

function beforeSubmit(){
	
      var planTime=$("#planTime").val();
      //alert(planTime);
      var reg=/^[1-2]{1}[0-9]{3}(\-){1}(0[0-9]{1}|1[0-2]{1}){1}(\-)(0[0-9]{1}|1[0-9]{1}|2[0-9]{1}|3[0-1]{1}){1}$/;
      var isMatch=reg.test(planTime);
      if(isMatch){
    	  return [true,''];
      }else{
    	  return [false,'请填写有效日期 yyyy-MM-dd']
      }




}

  function initJqGridHideBtn(){
	  $("#add_gridTable").hide();
      $("#edit_gridTable").hide();
      $("#del_gridTable").hide();
  }

     var setting = {
            async: {
                enable: true,
                url: '${request.contextPath}/admin/shipVoyageTree.action',
                datatype : 'json',
                autoParam:["id","name","level","flag"]
            },
            data: {
                simpleData: {
                       enable: true
                }
            },
            callback:{
                onNodeCreated : zTreeonNodeCreated,
                onClick:zTreeClick
            }
            
        };
 
    function zTreeClick(event,treeId,treeNode){
    //var flag=treeNode.FLAG;
      //  alert(flag);
        var a=treeNode.id;
          //alert(a);
          a=a.replace("C","");
          var b=treeNode.FLAG;
          //alert(b);
          if(b==0){
        	  $("#add_gridTable").show();
              $("#edit_gridTable").show();
              $("#del_gridTable").show();
              jQuery("#gridTable").jqGrid('setGridParam',{
                  url : "${request.contextPath}/list!list.action?voyageId="+a,
                  page : 1 
              });
              jQuery("#gridTable").trigger('reloadGrid');

          }else{
        	  $("#add_gridTable").hide();
              $("#edit_gridTable").hide();
              $("#del_gridTable").hide();
        	  jQuery("#gridTable").jqGrid('setGridParam',{
                  url : "${request.contextPath}/list!list.action?voyageId="+a,
                  page : 1 
              });
              jQuery("#gridTable").trigger('reloadGrid');
          }
        	  
          }
        //alert(a);
           
        function zTreeonNodeCreated(event,treeId,treeNode){
        var treeObj=$.fn.zTree.getZTreeObj(treeId);
        var list=treeObj.getNodeByParam("level",'1');
        treeObj.expandNode(list,true,true,true);
     
     
     }

        jQuery(document).ready(function(){
            $.fn.zTree.init($("#shipTree"), setting);
        });
        
  function fillVoyageId(params,postdata){
	  
	  var treeObj=$.fn.zTree.getZTreeObj("shipTree");
      
      var nodes=  treeObj.getSelectedNodes();

      var add_data=new Object();

      var a=nodes[0].id;

      a=a.replace("C","");

      add_data["voyageId"]=a;

      add_data["beanName"] = "tsm.TsmVoyageDynamic";
      
      return add_data;
	  
  }
        
        
        
$(function(){
    $("#gridTable").jqGrid({
    //list表格获取地址
        //list表格数据获取地址
        url:'${request.contextPath}/list!list.action',
        //list表格编辑地址
        editurl :'${request.contextPath}/operator.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        width: 880,
        colNames:['动态编号','航次编码','名称','港口','计划时间','实际时间','备注','状态','创建人','创建日期','最后修改人','最后修改时间'],
        colModel:[
            {name:'dynamicId',jsonmap:'DYNAMIC_ID',index:'DYNAMIC_ID',editable:false,hidden:true},          
            {name:'voyageId',jsonmap:'VOYAGE_ID',index:'VOYAGE_ID',editable:false,hidden:true},     
            {name:'dynamicName',jsonmap:'DYNAMIC_NAME',editrules:{required:true},editable:true,index:'DYNAMIC_NAME'},      
            {name:'port',jsonmap:'PORT',editable:true,index:'PORT',editrules:{required:true}},
            {name:'planTime',jsonmap:'PLAN_TIME',editable:true,index:'PLAN_TIME',editrules:{required:true},
                  editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}     
            },
            {name:'realTime',jsonmap:'REAL_TIME',index:'REAL_TIME',editable:false,hidden:true,
                  editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}     
             
            },
            {name:'remark',jsonmap:'REMARK',index:'REMARK',editable:true},
            {name:'status',jsonmap:'STATUS',index:'STATUS',editable:false,hidden:true,
              
            },
            {name:'createdBy',jsonmap:'CREATED_BY',editable:false,hidden:true},
            {name:'createdDate',jsonmap:'CREATED_DATE',editable:false,hidden:true,
                editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}       
            },
            {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:false,hidden:true},
            {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,
              editoptions :  {dataInit: function(element) {
                    $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                }}  
            }     
        ],
        sortname:'DYNAMIC_ID',
        sortorder:'ASC',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        rowNum : 20,
        altRows:true,
        rowList : [10,20,30],
        //onSelectRow:cellSelect,
        jsonReader : {
            page : "page.pageNo",
            total : "page.totalPages",
            records : "page.totalCount",
            root : "page.result",
            repeatitems : false,
            id : 'DYNAMIC_ID'
        },
        
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
            //设置访问的list标签
            settings.data=settings.data+ "&gridKey=/list/operation#TsmVoyageDynamic";
            return true;
        },
        pager : "#gridPager",
        caption : "航次动态列表"
    }).navGrid('#gridPager',{
            edit:true,
            //editfunc:editVoyage,
            add:true, 
            //addfunc:addVoyage,
            del:true, 
            //delfunc:delVoyage,
            search: false
    },{ 
        //edit
        beforeSubmit:beforeSubmit,
        reloadAfterSubmit:true,
        closeAfterEdit:true,//新增完毕后关闭
        afterComplete:opertaionPrompt,//更新结束后提示信息
        onclickSubmit: fillVoyageId  //触发的事件
    },{
    //add
    	beforeSubmit:beforeSubmit,
        reloadAfterSubmit : true,
        closeAfterAdd : true, //新增完毕后关闭
        afterComplete : opertaionPrompt,
        onclickSubmit: fillVoyageId
    },{
      //del
        reloadAfterSubmit : true, 
        closeAfterEdit : true,  //修改完毕后关闭
        afterComplete : opertaionPrompt, //更新结束后提示信息
        onclickSubmit: fillVoyageId,    
        
    });
    initJqGridHideBtn();
    
});

$(function(){
 $("#time").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat : 'yy-mm-dd'
        });
$("#editTime").datepicker({
            changeMonth: true,
            changeYear: true,
            dateFormat : 'yy-mm-dd'
        });


})


var addVoyage=function(){
    var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
    alert(a);
    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可编辑");
   }else{
     var consoleDlg = $("#gridDialog");   
     var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
     //consoleDlg.find("#code").removeAttr().val();
      //consoleDlg.find("#route").removeAttr().val();
     consoleDlg.dialog("option", "title", "添加记录").dialog("open"); 
 }
    
}
   $("#gridDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
    
         buttons: {//为对话框添加按钮
         "确定":addUser,
         "取消":function() {$("#gridDialog").dialog("close")}
       }
     
});  
 function addUser(){
     var gd =$("#gridDialog");
     var dynamicName=$.trim(gd.find("#code").val());
      var port=$.trim(gd.find("#route").val());
      var planTime=$.trim(gd.find("#time").val());
      var reg=/^[1-2]{1}[0-9]{3}(\-){1}(0[0-9]{1}|1[0-2]{1}){1}(\-)(0[0-9]{1}|1[0-9]{1}|2[0-9]{1}|3[0-1]{1}){1}$/;
       var isMatch=reg.test(planTime);
       //alert(isMatch);
       if(isMatch){
       var remark=$.trim(gd.find("#remark").val());
      alert(remark);
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var id=nodes[0].id;
    
      id=id.replace("C","");
      alert(id);  
     $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{'dynamicName':dynamicName,"port":port,"planTime":planTime,"remark":remark,"oper":"add","beanName":"tsm.TsmVoyageDynamic","voyageId":id},
            dataType : 'json',
            success:function(result){
                alert(result.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#gridDialog").dialog("close")
            }
        });
     
       }else{
       alert("请输入有效日期格式，yyyy-MM-dd");
       return false;
       }
 }  
 
 var editVoyage=function(){
    var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
    alert(a);
    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可编辑");
   }else{
      var selectedId = $("#gridTable").jqGrid(
            "getGridParam", "selrow");
      var dynamicName=jQuery("#gridTable").jqGrid('getRowData',selectedId).dynamicName;
      var port=jQuery("#gridTable").jqGrid('getRowData',selectedId).port;
      var planTime=jQuery("#gridTable").jqGrid('getRowData',selectedId).planTime;
      var remark=jQuery("#gridTable").jqGrid('getRowData',selectedId).remark;
            
     var consoleDlg = $("#editDialog");   
     var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
     
     consoleDlg.find("#editName").removeAttr().val(dynamicName);
     consoleDlg.find("#editPort").removeAttr().val(port);
     consoleDlg.find("#editTime").removeAttr().val(planTime);
     consoleDlg.find("#editRemark").removeAttr().val(remark);
     consoleDlg.dialog("option", "title", "编辑记录").dialog("open"); 
 }
    
}
 

  $("#editDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
    
         buttons: {//为对话框添加按钮
         "确定":editUser,
         "取消":function() {$("#gridDialog").dialog("close")}
       }
     
});  
  
  function editUser(){
     var gd =$("#editDialog");
     var planTime=$.trim(gd.find("#editTime").val());
      var reg=/^[1-2]{1}[0-9]{3}(\-){1}(0[0-9]{1}|1[0-2]{1}){1}(\-)(0[0-9]{1}|1[0-9]{1}|2[0-9]{1}|3[0-1]{1}){1}$/;
       var isMatch=reg.test(planTime);
       //alert(isMatch);
       if(isMatch){
       var port=$.trim(gd.find("#editPort").val());
      var dynamicName=$.trim(gd.find("#editName").val());
      var remark=$.trim(gd.find("#editRemark").val());
      //alert(remark);
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var id=nodes[0].id;
    
      id=id.replace("C","");
      //alert(id);  
      var selectedId = $("#gridTable").jqGrid("getGridParam", "selrow")
            var dynamicId=jQuery("#gridTable").jqGrid('getRowData',selectedId).dynamicId;
      
     $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{'dynamicName':dynamicName,"port":port,"planTime":planTime,"remark":remark,"oper":"edit","beanName":"tsm.TsmVoyageDynamic","voyageId":id,"id":dynamicId},
            dataType : 'json',
            success:function(result){
                alert(result.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#editDialog").dialog("close")
            }
        });
     
       }else{
       alert("请输入有效日期格式，yyyy-MM-dd");
       return false;
       }
 }  
 
 var delVoyage=function(){
      var treeObj=$.fn.zTree.getZTreeObj("shipTree");
    //alert(treeObj);
      var nodes=treeObj.getSelectedNodes();
    //alert(nodes);
    var a=nodes[0].FLAG;
    alert(a);
    var reg=/^1$/;
   var isMatch=reg.test(a);
   //alert(isMatch);
   if(isMatch){
     alert("已起航，不可删除");
   }else{
      var consoleDlg = $("#delDialog");   
      var dialogButtonPanel = consoleDlg.siblings(".ui-dialog-buttonpane"); 
      consoleDlg.dialog("option", "title", "确定删除记录？").dialog("open"); 

   }
 
 }
 $("#delDialog").dialog({  
         autoOpen: false,      
         modal: true,    // 设置对话框为模态（modal）对话框  
         resizable: true,      
         width: 480,  
         buttons: {//为对话框添加按钮
         "确定":delUser,
         "取消":function() {$("#delDialog").dialog("close")}
       }
     
});
 function delUser(){
      var selectedId = $("#gridTable").jqGrid(
            "getGridParam", "selrow");
          $.ajax({
            url: '${request.contextPath}/operator.action',
            type:'post',
            data:{"oper":"del","beanName":"tsm.TsmVoyageDynamic","id":selectedId},
            dataType : 'json',
            success:function(request){
            alert(request.message);
                jQuery("#gridTable").trigger('reloadGrid');      
                $("#delDialog").dialog("close")
            }
        });
      
 }
</#macro>
<#macro main>
  <div id="treediv" class="ui-widget-content ui-corner-all" style="margin:30px 10px 20px -20px;float:left;width:200px;">
           <ul id="shipTree" class="ztree"></ul>
  </div>
  <div id="detaildiv" style="margin:30px 40px 20px 0px;float:left;width:200px">
           <table id="gridTable"></table>
           <div id="gridPager"></div>
  </div>
  <div id="gridDialog" style="visibility:hidden">  
                <form id="consoleForm">  
                    <input type="hidden" id="selectId" />  
                    <table class="formTable" id="dialogId">  
                        <tr>  
                            <th><span class="ui-widget-header">动态名称</span></th>  
                            <td>  
                                <input type="text" class="textField" id="code" name="code" />  
                            </td>  
                            
                        </tr>
                        <tr>
                        <th><span class="ui-widget-header">港口</span></th>  
                            <td>  
                                <input type="text" class="textField" id="route" name="route" />  
                            </td>   
                        </tr>  
                        <tr>
                        <th><span class="ui-widget-header">计划时间</span></th>  
                            <td>  
                                <input type="text" class="textField" id="time" name="time" />  
                            </td>   
                        </tr>     
                        <tr>
                        <th><span class="ui-widget-header">备注</span></th>  
                            <td>  
                                <input type="text" class="textField" id="remark" name="remark" />  
                            </td>   
                        </tr>  
                    </table>  
                </form>  
            </div>  
      
    
    </div>
    <div id="editDialog" style="visibility:hidden">  
                <form id="consoleForm">  
                    <input type="hidden" id="selectId" />  
                    <table class="formTable" id="dialogId">  
                        <tr>  
                            <th><span class="ui-widget-header">动态名称</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editName" name="editName" />  
                            </td>  
                            
                        </tr>
                        <tr>
                        <th><span class="ui-widget-header">港口</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editPort" name="editPort" />  
                            </td>   
                        </tr>  
                        <tr>
                        <th><span class="ui-widget-header">计划时间</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editTime" name="editTime" />  
                            </td>   
                        </tr>     
                        <tr>
                        <th><span class="ui-widget-header">备注</span></th>  
                            <td>  
                                <input type="text" class="textField" id="editRemark" name="editRemark" />  
                            </td>   
                        </tr>  
                    </table>  
                </form>  
            </div>  
      
    
    </div>
    <div id="delDialog">
      
    
    </div>
</#macro>
        
        
        
        
        